#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->tabWidget->setVisible(false);
    ui->tabWidget->tabsClosable();

    this->setWindowState(Qt::WindowMaximized);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_action_new_window_triggered()
{
    NewFormDoc *newWindow = new NewFormDoc(this);
    newWindow->setAttribute(Qt::WA_DeleteOnClose);
    int curIndex = ui->tabWidget->addTab(newWindow, "+new");
    ui->tabWidget->setCurrentIndex(curIndex);
    ui->tabWidget->setVisible(true);

}

void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
    if (index < 0) return;

    QWidget* tab = ui->tabWidget->currentWidget();
    tab->close();
}

void MainWindow::on_action_dialog_window_triggered()
{
    NewFormDoc *newWindow = new NewFormDoc();
    newWindow->setAttribute(Qt::WA_DeleteOnClose);

    newWindow->show();
}
